//
//  main.m
//  03_wok
//
//  Created by dllo on 16/7/6.
//  Copyright © 2016年 yh. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Book.h"
#import "BookManager.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
#if 0
        // 1. 截取字符串 "20|https://www.baidu.com" 中 "|" 前面和后⾯的字符串, 并输出
        NSString *str = @"20|https://www.baidu.com";
        NSArray *arr = [str componentsSeparatedByString:@"|"];
        NSString *firstStr = arr[0];
        NSString *secStr = arr[1];
        NSLog(@"firstStr: %@, secStr: %@", firstStr, secStr);
        
        // 2. 向可变数组里存储 int、float、double、BOOL类型等数据(不能使用字面量)
        int a = 7;
        float b = 7.7;
        double c = 7.7777;
        BOOL d = 1;
        NSNumber *numA = [NSNumber numberWithInt:a];
        NSNumber *numB = [NSNumber numberWithFloat:b];
        NSNumber *numC = [NSNumber numberWithDouble:c];
        NSNumber *numD = [NSNumber numberWithBool:d];
        NSMutableArray *array = [NSMutableArray arrayWithObjects:numA, numB, numC, numD, nil];
        NSLog(@"%@", array);
#endif
        // 3. 实现图书管理系统(BookManager类)：
        // 使用数组管理所有书籍(Book类)。
        // BookManager类属性数组可以添加、删除。
        // 可以从数组根据书名查找书籍，并修改书籍的价格。
        // 展示所有书籍清单（书名）
        Book *book1 = [[Book alloc] initWithBookName:@"三国演义" price:50];
        Book *book2 = [[Book alloc] initWithBookName:@"水浒传" price:40];
        Book *book3 = [[Book alloc] initWithBookName:@"红楼梦" price:80];
        Book *book4 = [[Book alloc] initWithBookName:@"西游记" price:60];
        Book *book5 = [[Book alloc] initWithBookName:@"你的孤独虽败犹荣" price:55];
        BookManager *manager = [BookManager alloc];
        manager.bookArray = [[NSMutableArray alloc] initWithObjects:[book1 bookName], [book2 bookName], [book3 bookName], [book4 bookName], [book5 bookName], nil];
        // 添加书籍
        [manager.bookArray addObject:@"聊斋志异"];
        NSLog(@"%ld", manager.bookArray.count);
        NSLog(@"添加书籍聊斋志异成功");
        // 删除书籍
        [manager.bookArray removeObject:@"聊斋志异"];
        NSLog(@"删除书籍聊斋志异成功");
        // 根据书名 查找书籍
        BOOL a = [manager.bookArray containsObject:@"红楼梦"];
        if (a) {
            NSLog(@"您所查找的书籍存在, 排列在%ld号", [manager.bookArray indexOfObject:@"红楼梦"] + 1);
            book3 = [[Book alloc] initWithBookName:@"红楼梦" price:90];
            NSLog(@"修改红楼梦价格成功");
        } else {
            NSLog(@"您所查找的书籍 不存在 请更换书籍");
        }
        // 输出所有书籍
        for (NSInteger i = 0; i < manager.bookArray.count; i++) {
            NSLog(@"%@", manager.bookArray[i]);
        }
    }
    return 0;
}
